From: Ludovic CHEVALIER Date: Fri, 3 Nov 2017 17:01:02 +0000 (+0100) Subject: [MODULE] +constraints: a non-student can't be scholarship X-Git-Url: http://git.cyclocoop.org/data/%27%20.%20mediabox_timestamp%28find_in_path%28%27javascript/%7B%24www_url%7Dadmin/compta/operations/%40%20%27info_etape_suivante_2%27%20=%3E%20%27You%20can%20move%20on%20to%20the%20next%20step.%27%2C%20%27info_exceptions_proxy%27%20=%3E%20%27Exceptions%20for%20the%20proxy%27%2C%20%27info_exportation_base%27%20=%3E%20%27export%20database%20to%20%40archive%40%27%2C-%27info_facilite_suivi_activite%27%20=%3E%20%27To%20simplify%20monitoring%20of%20the%20site/%27s%20editorial;-%20%20activities%2C%20SPIP%20can%20send%20rmail%20notifications%2C%20e.g.%20to%20an%20editors/%27%20.%20generer_url_entite%28%24plugin%5B%27id_plugin%27%5D%2C%20%27plugin%27%29%20.%20%27?a=commitdiff_plain;h=66a7e6d4a80f4c5108e129800efb54f160df2169;p=burette%2Feturecup.git [MODULE] +constraints: a non-student can't be scholarship --- diff --git a/eturecup.py b/eturecup.py index 14a3298..5f58510 100644 --- a/eturecup.py +++ b/eturecup.py @@ -44,10 +44,12 @@ class Partner(orm.Model): partners = self.browse(cr, uid, ids) occupations = self.pool.get('bikecoop.partner.theme') for partner in partners: - v['is_student'] = False occupation = occupations.browse(cr, uid, occupation_id) if occupation.type == 'studies': v['is_student'] = True + else: + v['is_student'] = False + v['is_scholarship'] = False return {'value': v} _columns = { @@ -55,17 +57,32 @@ class Partner(orm.Model): 'Do you want to receive our monthly newsletter?'), 'is_student': fields.function(_get_bikecoop_theme_type, method=True, - string='Is this partner a student?', + string='Student?', type='boolean', store=True), - 'scholarship': fields.boolean('Scholarship', - help='Is this student a scholarship?'), + 'is_scholarship': fields.boolean('Scholarship', + help='Is this student a scholarship?'), 'want_to_be_volunteer': fields.boolean( 'Do you want to receive some informations about volunteer \ activities?', help='… in company and its activities: bikecoop, events, …'), } + def _check_occupation_is_not_studies(self, cr, uid, ids, context=None): + """Check if partners are students. If not, they can't be + scholarships.""" + partners = self.browse(cr, uid, ids, context=context) + for partner in partners: + if partner.occupation_id.type != 'studies': + if partner.is_scholarship: + return False + return True + + _constraints = [ + (_check_occupation_is_not_studies, 'Error: This partner can\'t be a\ + scholarship because s·he isn\'t a student.', ['is_scholarship']), + ] + class Theme(orm.Model): _inherit = 'bikecoop.partner.theme' diff --git a/view/bikecoop.xml b/view/bikecoop.xml index 558ba6b..7f53346 100644 --- a/view/bikecoop.xml +++ b/view/bikecoop.xml @@ -40,7 +40,7 @@ - +